<?php

class Admin_Form_Atualizacaosistema extends Zend_Form
{
    public function init() {
   	    
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        $urlbase = $front->getBaseUrl();
        
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        
        $this->setName('form_pdr');
        
        $id = $front->getRequest()->getParam('id');
        
        $el = new Zend_Form_Element_Hidden('ATS_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        if($id == 0){
            $el = new Zend_Form_Element_File('ATS_FILE');
            $el->setLabel('Arquivo de atualização')
            ->addValidator('Extension', false, array('sql'));
            $this->addElement($el);
        }
        
       if($id > 0){
            
            $html = '<table id="tlist" style="width:900px">';
            $html .= '<tr><th style="width:130px">Log</th><th style="width:770px">Comandos</th><tr>';
            $query = 'SELECT SQL_CACHE * FROM ATUALIZACAO_EXECUTADO WHERE ATS_ID = '.$id;
            $result = $db->fetchAll($query);
            foreach($result as $row){
                $html .= '<tr><td>'.($row['ATX_DATHOR']).'</td><td>'.$row['ATX_SQL'].'</td><tr>';
            }
            $html .= '</table>';
            $el = new Zend_Form_Element('html',array( 'helper'=>'formNote', 'value'=> $html ));
            $this->addElement($el);
        }
        

        if($id == 0){
            $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
            $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
            $btn->setLabel('Salvar');
            $btn->setAttrib('id', 'submitbutton');
            $btn->setAttrib('class', 'btn-frm');
            $this->addElement($btn);
        }
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
        
    }

}

